<?php
/**
 *
 * Projet Authentic CMS
 * @file 	   router.php
 *
 * PHP version 5
 *
 *
 * @author     Poly Charly <CharlyPoly@gmail.fr>
 * @copyright  2009 Authentic Development Group
 * @license    GNU General Public License v3
 * @since      File available since Version 0.1.0
 * 
 */

class router {
	private $module			= NULL;
	private $controller		= NULL;
	private $action			= NULL;
	private $args			= array();
	
	private $isAdmin		= FALSE;
	
	public function __construct($DefaultModule, $siteBase) {
		$this->getRequest($DefaultModule, $siteBase);
	}
	
	public function isAdmin() {
		return $this->isAdmin;
	}
	
	public function getController() {
		return $this->controller;
	}
	
	public function getAction() {
		return $this->action;
	}
	
	public function getArgs() {
		return $this->args;
	}
	
	public function moveFoward($nb) {
		
	}
	
	
	
	//  #PRIVATES
	
	private function getRoute($r, $dc) { //  # index.php/blog/show/ticket/1
		$a 					= explode('/', $r);
		$ParamsLength		= count($a);
		foreach( $a as $k=>$v ) {
			if ($ParamsLength > 2 && $k > 2) {
				$this->args[] = $v;
			}
		}
		
		$this->controller 		= (isset($a[1]) && !empty($a[1])) ? $a[1] : $dc;
		if ($this->controller == "Manager") $this->isAdmin = TRUE;
		$this->action 	= (isset($a[2]) && !empty($a[2])) ? $a[2] : 'index';
	}

	
	private function getRequest($DefaultModule, $siteBase) {
		$request = str_replace(array($_SERVER['SCRIPT_NAME'],$_SERVER['QUERY_STRING'], $siteBase), '', $_SERVER['REQUEST_URI']);
		$request = str_replace('?', '', $request);
		$this->getRoute($request, $DefaultModule);
	}
}
?>